<!--单位基本情况普查表-->
<template>
  <Layout>
    <Form ref="queryForm" :model="dataToQuery" :label-width="120">
      <Row class="query-form">
        <Col span="8">
          <FormItem label="填报二级集团：" prop="twoLevelOrgName">
            <Select v-model="dataToQuery.twoLevelOrgName" filterable>
              <Option v-for="item in twoLevelOrgs" :value="item.orgName" :key="item.orgId">{{ item.orgName }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label='填报单位：'>
            <Select clearable filterable style="width:300px" v-model="dataToQuery.companyName" placeholder="请选择企业"
                    :remote-method="remoteMethodSelectOrg"
                    :default-label="defaultLabel"
                    :loading="orgLoading">
              <Option v-for="(option, index) in orgLists" :value="option.orgName" :key="index">{{ option.orgName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-if="!switchFlag">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
        <Col span="8" v-else>
          <FormItem label="年度：" prop="year1" >
              <DatePicker class="query-form-el" type="year" placeholder="请选择年度" v-model="dataToQuery.year1" :clearable="false"
                          @on-change="()=>{if(dataToQuery.year1 instanceof Date){dataToQuery.year = dataToQuery.year1.getFullYear().toString()}}"></DatePicker>
          </FormItem>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
          <FormItem label='填报类别：' prop='categoryType'>
            <Radio-group v-model="dataToQuery.categoryType">
              <Radio label="1">第一次申报</Radio>
              <Radio label="2">变更申报</Radio>
            </Radio-group>
          </FormItem>
        </Col>
        <Col span="16">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
          <download-button :api="exportUrl" :queryForm="dataToQuery" />
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据!" @on-selection-change='getSelectRows'
      @on-sort-change="sortChange" :loading='pageStatus.loading ||  pageStatus.baseLoading'
           border :columns="columns1" :data="dataTable">
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24">
        <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
              @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer
              show-elevator/>
      </Col>
    </Row>
    <Modal :mask-closable="false" :title="mode == 'view' ?'单位基本情况普查表详情':'单位基本情况普查表'" :transfer=false
           v-model="dialogShow" v-if="dataToView && dialogShow"
           :width=900 :styles="{height:'559px'}" class-name='limit-height-dialog'>
      <Row>
        <Col span="24">
          <Form ref="dataToView" :class="mode === 'view'?'modal-view-detail':'modal-form'" :show-message="false"
                :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"
                :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?160:null">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='填报单位：' prop='companyId'>
                  <div v-if="mode === 'view'">{{ dataToView.companyName }}</div>
                  <cascaderDom v-else class="query-form-el" ref="groupOrg"
                               @setOrgInfo='(data)=>{cascaderDomIdChangeHandle(data,"companyId");}'
                               @setOrgname='(data)=>{cascaderDomNameChangeHandle(data,"companyName");}'
                               :currentOrgId="dataToView.companyId"
                               :setCurrentName="{label:dataToView.companyName, value:dataToView.companyId}"
                               :orgTree="true"></cascaderDom>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='组织机构代码：'>
                  <div v-if="mode === 'view'">{{ dataToView.companyCode }}</div>
                  <Input v-else class='' placeholder="请填写组织机构代码" type='text'
                         v-model='dataToView.companyCode'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='成立时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.establishDate) }}</div>
                  <DatePicker v-else class="w" placeholder="请选择成立时间"
                              v-model='dataToView.establishDate'></DatePicker>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='法人单位：'>
                  <div v-if="mode === 'view'">{{ dataToView.legalCompany }}</div>
                  <Input v-else class='' placeholder="请填写法人单位" type='text'
                         v-model='dataToView.legalCompany'></Input>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='法人(单位负责人)：'>
                  <div v-if="mode === 'view'">{{ dataToView.legalPersion }}</div>
                  <Input v-else class='' placeholder="请填写法人(单位负责人)" type='text'
                         v-model='dataToView.legalPersion'></Input>
                </FormItem>

              </Col>
              <Col span="11">
                <FormItem label='联系电话：'>
                  <div v-if="mode === 'view'">{{ dataToView.phone }}</div>
                  <Input v-else class='' placeholder="请填写联系电话" type='text' maxlength="20"
                         v-model='dataToView.phone'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='单位注册地址：'>
                  <div v-if="mode === 'view'">{{ dataToView.companyRegisterAddress }}</div>
                  <Input v-else class='' placeholder="请填写单位注册地址" type='textarea' maxlength="1024"
                         v-model='dataToView.companyRegisterAddress'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='作业地址：' prop='taskAddress'>
                  <div v-if="mode === 'view'">{{ dataToView.taskAddress }}</div>
                  <Input v-else class='' placeholder="请填写作业地址" type='textarea'
                         v-model='dataToView.taskAddress'></Input>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">

              <Col span="11">
                <FormItem label='填报类别：' prop='categoryType'>
                  <div v-if="mode === 'view'">{{ dataToView.categoryType == '1' ? '第一次申报' : '变更申报' }}</div>
                  <Radio-group v-else v-model="dataToView.categoryType" @on-change="radioCategoryType">
                    <Radio label="1">第一次申报</Radio>
                    <Radio label="2">变更申报</Radio>
                  </Radio-group>

                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='变更原因：'>
                  <div v-if="mode === 'view'">{{ dataToView.reasonChange }}</div>
                  <Input v-else class='' :disabled="reason" placeholder="请填写变更原因" type='text'
                         v-model='dataToView.reasonChange'></Input>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='邮编：'>
                  <div v-if="mode === 'view'">{{ dataToView.zipCode }}</div>
                  <Input v-else class='' placeholder="请填写邮编" type='text' v-model='dataToView.zipCode'></Input>
                </FormItem>
              </Col>

              <Col span="11">
                <FormItem label='职业卫生负责人：' prop='healthDirector'>
                  <div v-if="mode === 'view'">{{ dataToView.healthDirector }}</div>
                  <Input v-else class='' placeholder="请填写职业卫生负责人" type='text'
                         v-model='dataToView.healthDirector'></Input>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='职业卫生负责人联系电话：' prop='healthPhone'>
                  <div v-if="mode === 'view'">{{ dataToView.healthPhone }}</div>
                  <Input v-else class='' placeholder="请填写职业卫生负责人联系电话" type='text'
                         v-model='dataToView.healthPhone'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='职业卫生管理机构：' prop='manageOrg'>
                  <div v-if="mode === 'view'">{{ dataToView.manageOrg }}</div>
                  <Input v-else class='' placeholder="请填写职业卫生管理机构" type='text'
                         v-model='dataToView.manageOrg'></Input>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='注册类型：'>
                  <div v-if="mode === 'view'">{{ dataToView.registerType }}</div>
                  <Input v-else class='' placeholder="请填写注册类型" type='text'
                         v-model='dataToView.registerType'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='所属行业：'>
                  <div v-if="mode === 'view'">{{ dataToView.industry }}</div>
                  <Input v-else class='' placeholder="请填写所属行业" type='text' v-model='dataToView.industry'></Input>
                </FormItem>
              </Col>
            </Row>

            <!--<Row type="flex" justify="space-around" class="code-row-bg" >-->
            <!--<Col span="11">-->
            <!--<FormItem label='隶属关系：' >-->
            <!--<div v-if="mode === 'view'">{{ dataToView.subordination }}</div>-->
            <!--<Input v-else class=''placeholder="请填写隶属关系" type='text' v-model='dataToView.subordination'></Input>-->
            <!--</FormItem>-->
            <!--</Col>-->
            <!--<Col span="11">-->
            <!--<FormItem label='上级主管单位：' >-->
            <!--<div v-if="mode === 'view'">{{ dataToView.superCompany }}</div>-->
            <!--<Input v-else class=''placeholder="请填写上级主管单位" type='text' v-model='dataToView.superCompany'></Input>-->
            <!--</FormItem>-->
            <!--</Col>-->
            <!--</Row>-->

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='本单位职业危害等级：' prop='hazardLevel'>
                  <div v-if="mode === 'view'">{{ dataToView.hazardLevel }}</div>
                  <Select v-else v-model='dataToView.hazardLevel' clearable class='query-form-el'>
                    <Option value="一般">一般</Option>
                    <Option value="较重">较重</Option>
                    <Option value="严重">严重</Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='职业卫生管理现状评价时间：'>
                  <div v-if="mode === 'view'">{{ renderViewDate(dataToView.evaluationTime) }}</div>
                  <DatePicker v-else class='w' v-model="dataToView.evaluationTime" type="date"
                              placeholder="请输入"></DatePicker>
                </FormItem>
              </Col>
            </Row>

            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='实际从业人数：' prop='actualPersionNum'>
                  <div v-if="mode === 'view'">{{ dataToView.actualPersionNum }}</div>
                  <InputNumber v-else class='w' placeholder="请填写实际从业人数" min="0" type='text'
                               v-model='dataToView.actualPersionNum'></InputNumber>
                </FormItem>
              </Col>
              <!--<Col span="11">-->
              <!--<FormItem label='实际作业人数：' prop='actualWorkNum'>-->
              <!--<div v-if="mode === 'view'">{{ dataToView.actualWorkNum }}</div>-->
              <!--<InputNumber v-else class='w'placeholder="请填写实际作业人数" min="0" type='text' v-model='dataToView.actualWorkNum'></InputNumber>-->
              <!--</FormItem>-->
              <!--</Col>-->
              <!--</Row>-->

              <!--<Row type="flex" justify="space-around" class="code-row-bg" >-->
              <!--<Col span="11">-->
              <!--<FormItem label='实际作业人数(女)：' prop='actualWorkWomanNum'>-->
              <!--<div v-if="mode === 'view'">{{ dataToView.actualWorkWomanNum }}</div>-->
              <!--<InputNumber v-else class='w'placeholder="请填写实际作业人数(女)" min="0" type='text' v-model='dataToView.actualWorkWomanNum'></InputNumber>-->
              <!--</FormItem>-->
              <!--</Col>-->
              <Col span="11">
                <FormItem label='接触危害因素人数：' prop='exposureHazardousNum'>
                  <div v-if="mode === 'view'">{{ dataToView.exposureHazardousNum }}</div>
                  <InputNumber v-else class='w' placeholder="请填写接触危害因素人数" min="0" type='text'
                               v-model='dataToView.exposureHazardousNum'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='接触危害因素人数(女)：' prop='exposureHazardousWomanNum'>
                  <div v-if="mode === 'view'">{{ dataToView.exposureHazardousWomanNum }}</div>
                  <InputNumber v-else class='w' placeholder="请填写接触危害因素人数(女)" min="0" type='text'
                               v-model='dataToView.exposureHazardousWomanNum'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='职业危害作业场所数：' prop='hazardousNum'>
                  <div v-if="mode === 'view'">{{ dataToView.hazardousNum }}</div>
                  <InputNumber v-else class='w' placeholder="请填写职业危害作业场所数" min="0" type='text'
                               v-model='dataToView.hazardousNum'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='职业危害作业场所：' prop='hazardouArr'>
                  <Row v-for="(item,index) in dataToView.hazardouArr" :key="index">
                    <Col span="22">
                      <div v-if="mode === 'view'">{{ index + 1 + ":" + dataToView.hazardouArr[index] }}</div>
                      <Input v-else class='' placeholder="请填写职业危害作业场所" type='text'
                             v-model='dataToView.hazardouArr[index]'></Input>
                    </Col>
                    <Col span="2" v-if="mode !== 'view'">
                      <a v-if="index>0" style="font-size: 11px;color: red;margin-left: 3px"
                         @click="dataToView.hazardouArr.splice(index,1)">删除</a>
                      <a v-if="index==dataToView.hazardouArr.length-1" style="font-size: 11px;margin-left: 4px"
                         @click="dataToView.hazardouArr.push('')">新增</a>
                    </Col>
                  </Row>
                </FormItem>
              </Col>
            </Row>
            <!--<Row type="flex" justify="space-around" class="code-row-bg" >-->
            <!--<Col span="11">-->
            <!--<FormItem label='职业病危害因素类别数(种)：' prop='hazardCategoryNum'>-->
            <!--<div v-if="mode === 'view'">{{ dataToView.hazardCategoryNum }}</div>-->
            <!--<InputNumber v-else class='w'placeholder="请填写职业病危害因素类别数(种)" min="0" type='text' v-model='dataToView.hazardCategoryNum'></InputNumber>-->
            <!--</FormItem>-->
            <!--</Col>-->
            <!--<Col span="11">-->
            <!--<FormItem label='职业病危害因素数(个)：' prop='hazardFactorsNum'>-->
            <!--<div v-if="mode === 'view'">{{ dataToView.hazardFactorsNum }}</div>-->
            <!--<InputNumber v-else class='w'placeholder="请填写职业病危害因素数(个)" min="0" type='text' v-model='dataToView.hazardFactorsNum'></InputNumber>-->
            <!--</FormItem>-->
            <!--</Col>-->
            <!--</Row>-->
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='填报人：' prop='createUserName'>
                  <div v-if="mode === 'view'">{{ dataToView.createUserName }}</div>
                  <Input v-else class='' :readonly="true" placeholder="填报人" type='text'
                         v-model='dataToView.createUserName'></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='填报人联系电话：' prop='userPhone'>
                  <div v-if="mode === 'view'">{{ dataToView.userPhone }}</div>
                  <Input v-else class='' placeholder="填报人电话" type='text' v-model='dataToView.userPhone'></Input>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='主要产品：' prop='mainProduct'>
                  <div v-if="mode === 'view'">{{ dataToView.mainProduct }}</div>
                  <Input v-else class='' placeholder="请填写主要产品" type='textarea'
                         v-model='dataToView.mainProduct'></Input>
                </FormItem>
              </Col>
            </Row>
          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dataToView')">确定</Button>
        <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
        <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
      </div>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import {sessionStorage} from '@/common/cacheUtils.js';
import {formatDate} from '@/tools/index'
import pageCommonFunction from '@/components/pageCommonFunction.js'
import dangerList from "@/views/safe/treeYearAction/DangerListMod.vue";

var cascaderDom = () => import('@/components/cascader-dom.vue');
export default {
  components: {
    cascaderDom, dangerList
  },
  data() {
    return {
      ...this.createCommonDataField(),
      defaultLabel: sessionStorage('userId').getObject('userId').companyName,
      orgLists: [],
      userInfo: sessionStorage('userId').getObject('userId'),
      twoLevelOrgs: [],
      orgLoading: false,
      switchFlag: false,
      uploadFile: null,
      buttonLoading1: false,
      importModal: false,
      reason: false,
      token: sessionStorage('token').get('Authorization'),
      user: sessionStorage('userId').getObject('userId'),
      columns1: [
        {title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
        {key: 'companyName', title: '填报单位', align: 'center', minWidth: 170, tooltip: true},
        {key: 'companyCode', title: '组织机构代码', align: 'center', minWidth: 120},
        {key: 'establishDate', title: '成立时间', sortable: "custom", align: 'center', minWidth: 120, render: this.renderCellDate},
        {key: 'legalCompany', title: '法人单位', align: 'center', minWidth: 170, tooltip: true},
        {key: 'updateDate',sortable: "custom", title: '更新时间',align: 'center',minWidth: 120,render: this.renderCellDate},
        {key: 'legalPersion', title: '法人(单位负责人)', align: 'center', minWidth: 150},
        {key: 'phone', title: '联系电话', align: 'center', minWidth: 120},
        {key: 'companyRegisterAddress', title: '单位注册地址', align: 'center', minWidth: 200, tooltip: true},
        {key: 'taskAddress', title: '作业地址', align: 'center', minWidth: 200, tooltip: true},
        {key: 'zipCode', title: '邮编', align: 'center', minWidth: 120},
        {key: 'categoryType', title: '填报类别', align: 'center', minWidth: 120, render: this.renderCategoryType},
        {key: 'reasonChange', title: '变更原因', align: 'center', minWidth: 180, tooltip: true},
        {key: 'healthDirector', title: '职业卫生负责人', align: 'center', minWidth: 120},
        {key: 'healthPhone', title: '职业卫生负责人联系电话', align: 'center', minWidth: 120},
        {key: 'manageOrg', title: '职业卫生管理机构', align: 'center', minWidth: 120},
        {key: 'registerType', title: '注册类型', align: 'center', minWidth: 120},
        {key: 'industry', title: '所属行业', align: 'center', minWidth: 120},
        {key: 'hazardLevel', title: '本单位职业危害等级', align: 'center', minWidth: 100},
        {
          key: 'evaluationTime',sortable: "custom", 
          title: '职业卫生管理现状评价时间',
          align: 'center',
          minWidth: 100,
          render: this.renderCellDate
        },
        // { key:'subordination',title: '隶属关系',  align: 'center',minWidth: 150 },
        // { key:'superCompany',title: '上级主管单位',  align: 'center',minWidth: 150 },
        {key: 'actualPersionNum', title: '实际从业人数', align: 'center', minWidth: 120},
        // { key:'actualWorkNum',title: '实际作业人数',  align: 'center',minWidth: 120 },
        // { key:'actualWorkWomanNum',title: '实际作业人数(女)',  align: 'center',minWidth: 120 },
        {key: 'exposureHazardousNum', title: '接触危害因素人数', align: 'center', minWidth: 120},
        {key: 'exposureHazardousWomanNum', title: '接触危害因素人数(女)', align: 'center', minWidth: 120},
        {key: 'hazardousNum', title: '职业危害作业场所数', align: 'center', minWidth: 120},
        // { key:'hazardCategoryNum',title: '职业病危害因素类别数(种)',  align: 'center',minWidth: 120 },
        // { key:'hazardFactorsNum',title: '职业病危害因素数(个)',  align: 'center',minWidth: 120 },
        {key: 'mainProduct', title: '主要产品', align: 'center', minWidth: 120, tooltip: true},
        {key: 'userPhone', title: '填报人联系电话', align: 'center', minWidth: 120},
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          width: 200,
          align: 'center',
          render: (h, params) => {
            if (this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUserId || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                || sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined) {
              return h('div', [
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px',},
                  on: {
                    click: () => {
                      this.download(params);
                    }
                  }
                }, '导出'),
                h('Divider', {props: {type: 'vertical'}}, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px',},
                  on: {
                    click: () => {
                      this.viewData(params);
                    }
                  }
                }, '详情'),
                h('Divider', {props: {type: 'vertical'}}, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  disabled: true,
                  style: {fontSize: '14px'},
                  on: {
                    click: () => {
                      this.editData(params);
                    }
                  }
                }, '修改'),
                h('Divider', {props: {type: 'vertical'}}, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px', color: 'red'},
                  on: {
                    click: () => {
                      this.deleteData(params);
                    }
                  }
                }, '删除')
              ]);
            } else {
              return h('div', [
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px',},
                  on: {
                    click: () => {
                      this.download(params);
                    }
                  }
                }, '导出'),
                h('Divider', {props: {type: 'vertical'}}, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px',},
                  on: {
                    click: () => {
                      this.viewData(params);
                    }
                  }
                }, '详情'),
                h('Divider', {props: {type: 'vertical'}}, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px', color: '#c5c8ce'}
                }, '修改'),
                h('Divider', {props: {type: 'vertical'}}, ''),
                h('A', {
                  props: {type: 'primary', size: 'small'},
                  style: {fontSize: '14px', color: '#c5c8ce'}
                }, '删除')
              ]);
            }
          }
        }
      ],
      upUrl: Api.uploadDangerList,
      ruleCustom: {
        companyId: [{required: true, message: '请填写填报单位', trigger: 'change',}],
        companyCode: [{required: true, message: '请填写组织机构代码', trigger: 'change',}],
        establishDate: [{required: true, message: '请填写成立时间', trigger: 'change', type: 'date'}],
        legalCompany: [{required: true, message: '请填写法人单位', trigger: 'change',}],
        legalPersion: [{required: true, message: '请填写法人(单位负责人)', trigger: 'change',}],
        phone: [{required: true, message: '请填写联系电话', trigger: 'change',}],
        companyRegisterAddress: [{required: true, message: '请填写单位注册地址', trigger: 'change',}],
        taskAddress: [{required: true, message: '请填写作业地址', trigger: 'change',}],
        zipCode: [{required: true, message: '请填写邮编', trigger: 'change',}],
        categoryType: [{required: true, message: '请填写填报类别', trigger: 'change',}],
        reasonChange: [{required: true, message: '请填写变更原因', trigger: 'change',}],
        healthDirector: [{required: true, message: '请填写职业卫生负责人', trigger: 'change',}],
        healthPhone: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(value))) {
              callback(' ');
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        manageOrg: [{required: true, message: '请填写职业卫生管理机构', trigger: 'change',}],
        registerType: [{required: true, message: '请填写注册类型', trigger: 'change',}],
        industry: [{required: true, message: '请填写所属行业', trigger: 'change',}],
        subordination: [{required: true, message: '请填写隶属关系', trigger: 'change',}],
        superCompany: [{required: true, message: '请填写上级主管单位', trigger: 'change',}],
        actualPersionNum: [{required: true, message: '请填写实际从业人数', trigger: 'change', type: 'number'}],
        // actualWorkNum: [ { required: true, message: '请填写实际作业人数', trigger: 'change',type:'number'}],
        // actualWorkWomanNum: [ { required: true, message: '请填写实际作业人数(女)', trigger: 'change',type:'number'}],
        exposureHazardousNum: [{required: true, message: '请填写接触危害因素人数', trigger: 'change', type: 'number'}],
        exposureHazardousWomanNum: [{
          required: true,
          message: '请填写接触危害因素人数(女)',
          trigger: 'change',
          type: 'number'
        }],
        hazardousNum: [{required: true, message: '请填写职业危害作业场所数', trigger: 'change', type: 'number'}],
        // hazardCategoryNum: [ { required: true, message: '请填写职业病危害因素类别数(种)', trigger: 'change',type:'number'}],
        // hazardFactorsNum: [ { required: true, message: '请填写职业病危害因素数(个)', trigger: 'change',type:'number'}],
        mainProduct: [{required: true, message: '请填写主要产品', trigger: 'change',}],
        userPhone: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(value))) {
              callback(' ');
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],
        createUserName: [{required: true, message: '请填写填报人', trigger: 'change',}],

      },
      tableHeight: 10,
      crectification: [],
      // api
      standardSelectModal: false,
      queryUrl: Api.queryHealthBasic,
      exportUrl: Api.queryHealthBasic+ '/export',
      deleteUrl: Api.deleteHealthBasic,
      updateUrl: Api.updateHealthBasic,
      saveUrl: Api.saveHealthBasic,
      buttonLoading: false,
      dangerModel: false,
    }
  },
  mounted() {
    let _this = this;
    this.dataToQuery = {};
    this.setTableHeight();
    this.query();
    this.queryTwoOrgInfo();
  },
  methods: {

    ...pageCommonFunction,
    beforeEditDataTable(data) {
      data.forEach(m=>{
        m.cellClassName = {
          updateDate: (m.updateDate && new Date(m.updateDate).getFullYear() == new Date().getFullYear()) ? '' : 'table-info-cell-red',
        }
      })
      return data
    },
    queryTwoOrgInfo() {
      if (sessionStorage('userId').getObject('userId').companyId != '18000000') {
        this.twoLevelOrgs.push({
          orgId: sessionStorage('userId').getObject('userId').twoLevelOrgId,
          orgName: sessionStorage('userId').getObject('userId').twoLevelOrgName
        });
      } else {
        this.$http.get(Api.quqeryTwoOrgInfo).then(res => {
          this.twoLevelOrgs = res.data.data
        }).catch(e => {
        })
      }
    },
    remoteMethodSelectOrg(query) {
      if (query !== '') {
        this.orgLists = [];
        this.orgLoading = true;
        this.$http.get(Api.queryOrgList + "?companyId=" + this.userInfo.companyId + "&orgName=" + query + "&fromPage=1&pageSize=1000").then(res => {
          this.orgLists = res.data.data;
          this.orgLoading = false;
        }).catch(e => {
          this.orgLoading = false;
          this.$Message.error('请求失败');
        })
      } else {
        this.orgLoading = false;
      }
    },
    renderCategoryType(h, params) {
      let key = params.column.key;
      if (!params.row[key]) return "";

      if (params.row[key] == '1') {
        return h('span', '第一次申报')
      } else {
        return h('span', '变更申报')
      }


    },
    beforeViewDialogOpen(data) {
      if (data.row.hazardous) {
        data.row.hazardouArr = data.row.hazardous.split('#;#')
      }
    },
    beforeEditDialogOpen(data) {
      if (data.row.categoryType == '1') {
        this.reason = true;
      } else {
        this.reason = false;
      }
    },
    radioCategoryType(data) {
      if (data == '2') {
        this.reason = false;
      } else {
        this.reason = true;
      }
    },
    openDangerModal() {
      this.dangerModel = true;
    },
    selectDanger(row) {
      this.dangerModel = false;
      this.dataToView.dangerId = row.id;
      this.dataToView.dangerName = row.dangerName;
    },
    dictListToMap(arr, key = 'codingCodeId') {
      var map = {}
      arr.map(item => {
        map[item[key]] = item
      })
      return map
    },
    areaCodeToSortName(codeStr) {
      if (!codeStr || codeStr === "") return "";
      var arr = codeStr.split(',')
      var outArr = []
      arr.forEach(codingCodeId => {
        if (this.areaMap[codingCodeId]) {
          outArr.push(this.areaMap[codingCodeId].codingName)
        }
      })
      return outArr.join("·")
    },
    download(params) {
      this.buttonLoading = true
      this.$http.get(Api.downloadHealthBasic + params.row.id, {
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = "单位基本情况普查表(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading = false
      })
    },
    importDanger() {
      this.importModal = true;
    },
    uploadExcel(response, file, fileList) {
      //上传完成后执行代码
      if (response.status === 200) {
        this.$Message.success('导入成功');
        this.query()
      } else if (response.status === 201) {
        this.$Message.error("导入失败");
        this.query()
      }
    },
    deleteData(params) {
      this.deleteDateAjax(params);
    },
    switchQuery(flag) {
      this.switchFlag = flag;
      if (!this.switchFlag) {
        this.tableHeight = this.tableHeight + 33;
      } else {
        this.tableHeight = this.tableHeight - 33;
      }
    },
    setOrgId(data) {
      this.dataToQuery.companyId = data[data.length - 1];
    },
    setOrgName(data) {
      this.dataToQuery.companyName = data;
    },
    query() {

      this.queryAjax()
    },

    submit(name) {
      if (this.dataToView.hazardouArr && this.dataToView.hazardouArr.length > 0) {
        this.dataToView.hazardous = this.dataToView.hazardouArr.join('#;#')
      }
      this.submitAjax(name);
    },
    createEmptyDataToAdd() {
      this.reason = true;
      return {
        companyId: sessionStorage('userId').getObject('userId').companyId,
        companyName: sessionStorage('userId').getObject('userId').companyName,
        legalCompany: sessionStorage('userId').getObject('userId').companyName,
        categoryType: '1',
        actualPersionNum: 0,
        actualWorkNum: 0,
        actualWorkWomanNum: 0,
        exposureHazardousNum: 0,
        exposureHazardousWomanNum: 0,
        hazardousNum: 0,
        hazardCategoryNum: 0,
        hazardFactorsNum: 0,
        createUserName: this.user.userName,
        userPhone: this.user.mobileNumber,
        hazardouArr: [""]
      }
    },
    downloadFile() {
      this.buttonLoading = true
      this.$http.get(Api.downloadMeasuresList, {
        params: this.dataToQuery,
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = "措施清单(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading = false
      })
    },
  },
  watch: {},

}
</script>

<style lang='css' scoped>
@import '../../../../index.css';

.importDanger {
  display: inline-block
}
</style>
